<?php



		 if(!empty($_POST)){
        $link=db_connect('p301');//调用数据库链接函数
        // mysqli_query(参数1，参数2)是专门用来执行sql语句的
		//mysqli_query($link,'set names utf8');
		//从$_POST中或许提交的数据存储在临时变量中
		$username = $_POST['username'];
		$password = $_POST['password'];
		//编写sql查询语句将用户提交的用户名和密码充当查询的过滤条件(where)
		$spl = "SELECT * FROM  `admin` where `username` = '$username' and `password` = '$password'";
		// echo $spl;exit;
		//执行编写的SQL语句
		$qqq = mysqli_query($link,$spl);
		//$qqq、$www 变量名要规范，养成良好的习惯 李哥笔
        //从查询的结果集中提取真实的数据
		$www = mysqli_fetch_assoc($qqq);
        //判断变量是否为空来提示登录是否成功
		if(!empty($www)){
                // if ($_POST['code']==$_SESSION['code']) {
                         //判断用户是否勾选记住我
                         if(!empty($_POST['check'])){
                              setcookie('username',$username,time()+3600);
                              setcookie('password',$password,time()+3600);
                         }else{
                            //给用户取消记住我就清空cookie里的用户信息
                              setcookie('username','',0);
                              setcookie('password','',0);
                          }
                          //判断用户是否勾选自动登录
                         if(!empty($_POST['auto'])){
                              setcookie('auto_login',1,time()+3600);
                         }else{
                              setcookie('auto_login',0,0);
                          }
                         //给用户临时会话做个临时变量
                         $_SESSION['admin'] = $www ;
                         header('location:index.php?c=index&a=index&admin=1');

                // }else{
                //     echo '<script>alert("验证码错误");history.go(-1);</script>';
                //    }
		}else{
			echo '<script>alert("用户名或者密码错误");history.go(-1);</script>';
		 }
  }
   include_once (VIEW_LAYER.'/admin/admin/login.html');